﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autofac;

namespace IOCSolution.Autofac
{
    public class AutofacRunner : IRunner
    {
        private IContainer _container;

        public string Name
        {
            get { return "Autofac"; }
        }

        public void Init()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<SqlDatabase>().As<IDatabase>();
            builder.RegisterType<DatabaseHelper>().SingleInstance();

            _container = builder.Build();
        }

        public void Start()
        {
            Console.WriteLine("\r\nthis name: " + Name);
            var manager = _container.Resolve<DatabaseHelper>();
            manager.Search("select * from users");
        }
    }
}
